package com.theaf.basemodule.common.dto.resource;

import com.theaf.basemodule.common.model.SysResource;
import com.theaf.core.utils.BeanMapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author:songwenke
 * @Description:资源
 * @Date:create in 16:26 2018/1/15
 * @author swk
 * @Modified By:
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResourceDTO {
    private Long id;
    @ApiModelProperty("父ID")
    private Long pid;
    @ApiModelProperty("父名称")
    private String pname;
    @ApiModelProperty("类型")
    private String type;
    @ApiModelProperty("类型名称")
    private String typeName;
    @ApiModelProperty("编码")
    private String code;
    @ApiModelProperty("为了全局唯一，编码路径，针对功能使用，前缀加系统编码和模块编码")
    private String codePath;
    @ApiModelProperty("名称")
    private String name;
    @ApiModelProperty("备注")
    private String remark;
    @ApiModelProperty("是否必选")
    private boolean musted;
    @ApiModelProperty("地址")
    private String url;
    @ApiModelProperty("缺省是否拥有")
    private boolean defaultVal;
    @ApiModelProperty(value = "是否启用")
    private Boolean enable;

    public static ResourceDTO fromPo(SysResource sysResource){
        ResourceDTO dto = BeanMapper.map(sysResource,ResourceDTO.class);
        if(sysResource.getSysResource()!=null) {
            dto.setPid(sysResource.getSysResource().getId());
            dto.setPname(sysResource.getSysResource().getName());
        }
        dto.setTypeName(sysResource.getType()==1?"系统":
                (sysResource.getType()==2?"模块":"功能"));
        return dto;
    }
}
